package com.example.baseapp.repository;

import com.example.baseapp.entity.Dish;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import java.util.List;

@Repository
public interface DishRepository extends JpaRepository<Dish, Long> {
    
    // 根据分类ID查询上架菜品
    List<Dish> findByCategoryIdAndStatusOrderByCreateTimeDesc(Long categoryId, Integer status);
    
    // 查询所有上架菜品
    @Query("SELECT d FROM Dish d WHERE d.status = 1 ORDER BY d.categoryId ASC, d.createTime DESC")
    List<Dish> findAllActiveOrderByCategory();
    
    // 根据状态查询菜品
    List<Dish> findByStatus(Integer status);
    
    // 根据分类ID查询菜品（管理员用）
    List<Dish> findByCategoryIdOrderByCreateTimeDesc(Long categoryId);
} 